local jihongwan = fk.CreateSkill{
  name = "lzsj__jihongwan",
  tags = { "Phase" },
}

Fk:loadTranslationTable{
  ["lzsj__jihongwan"] = "击红丸",
  ["#jihongwan_trigger"] = "击红丸",
  ["@@lzsj__jihongwan"] = "<font color=\"#E8251E\"><b>额外目标</b></font>",
  [":lzsj__jihongwan"] = "阶段技，你可视为对计算与你距离最远的角色使用一张光【杀】（无次数限制），若此时你计算与其距离较其计算你距离更近/为最近，其永久成为此技能的合法/额外目标。",
  ["#lzsj__jihongwan"] = "你可选择一名计算与你距离最远的角色，视为对其使用光杀",
  ["#AddTargetsBySkill"] = "由于 %arg 的效果，%from 使用的 %arg2 增加了目标 %to",
 
  ["$lzsj__jihongwan1"] = "白头山星火，终成燎原势！（백두산 성화, 마침내 불길이 되어!）",
  ["$lzsj__jihongwan2"] = "游击队的脚印，是共和国最初的疆界！（유격대의 발자국이 공화국의 첫 경계다!）",
}

jihongwan:addEffect("active", {
  anim_type = "control",
  prompt = "#lzsj__jihongwan",
  max_phase_use_time = 1,
  card_num = 0,
  target_num = 1,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected, selected_cards)
    if player:canUseTo(Fk:cloneCard("bright__slash"), to_select, {bypass_distances = true, bypass_times = true}) then
      return #selected == 0 and to_select ~= player and
      table.every(Fk:currentRoom().alive_players, function (p)
        return to_select:distanceTo(player) >= p:distanceTo(player)
      end)
    end
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local to = effect.tos[1]
    room:useVirtualCard("bright__slash", nil, player, to, jihongwan.name, true)
    if player:distanceTo(to) > to:distanceTo(player) then
      room:addPlayerMark(to, "lzsj__jihongwan")
    else
      if table.every(room:getOtherPlayers(player), function (p) return player:distanceTo(p) >= player:distanceTo(to) end) then
        room:addPlayerMark(to, "@@lzsj__jihongwan")
      end
    end
  end,
})

jihongwan:addEffect(fk.AfterCardTargetDeclared, {
  is_delay_effect = true,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(jihongwan.name) and data.card.trueName == "slash" and data.card.skillName == "lzsj__jihongwan" then
      return #data:getExtraTargets() > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = data:getExtraTargets()
    targets = table.filter(targets, function(p) return p:getMark("@@lzsj__jihongwan") > 0 end)
    for _, pid in ipairs(targets) do
      data:addTarget(pid)
    end
    room:sendLog{
      type = "#AddTargetsBySkill",
      from = player.id,
      to = table.map(targets, Util.IdMapper),
      arg = jihongwan.name,
      arg2 = data.card:toLogString()
    }
  end,
})

return jihongwan